﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;
using BLL;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
namespace WebApplication01.AssetHandel
{
    /// <summary>
    /// EmpolyHandler 的摘要说明
    /// </summary>
    public class EmpolyHandler : IHttpHandler
    {
        EmpolyBLL empbll = new EmpolyBLL();
        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string stype = context.Request["sType"];
            string result = string.Empty;
            if (stype == "list")
            {
                string empName = context.Request["empname"];
                // string depeList=context.Request["deptlist"];
                // string roleList = context.Request["rolelist"];
                // string Rdo = context.Request["rdo"];
                //列表展示
                int offset = Convert.ToInt32(context.Request["offset"]);
                int limit = Convert.ToInt32(context.Request["limit"]);
                int begin = offset + 1;
                int end = offset + limit;
                int total;
                List<EmployInfo> list = empbll.GetEmpoly(empName, begin, end, out total);
                JavaScriptSerializer s = new JavaScriptSerializer();
                var json = new
                {
                    total = total,
                    rows = list
                };
                result = s.Serialize(json);
                context.Response.Write(result);
            }
            else if (stype== "select") {
                string dept =context.Request["deptlist"];
                //string role =context.Request["rolelist"];
                List<EmployInfo> list = empbll.BindList(dept);
                result = JsonConvert.SerializeObject(list);
                context.Response.Write(result);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}